package org.htmlparser.tags;

import org.htmlparser.Node;
import org.htmlparser.scanners.ScriptScanner;
import org.htmlparser.util.SimpleNodeIterator;

public class ScriptTag extends CompositeTag
{
  private static final String[] mEndTagEnders;
  private static final String[] mIds;
  protected String mCode;

  static
  {
    String[] arrayOfString1 = new String[1];
    arrayOfString1[0] = "SCRIPT";
    mIds = arrayOfString1;
    String[] arrayOfString2 = new String[2];
    arrayOfString2[0] = "BODY";
    arrayOfString2[1] = "HTML";
    mEndTagEnders = arrayOfString2;
  }

  public ScriptTag()
  {
    setThisScanner(new ScriptScanner());
  }

  public String[] getEndTagEnders()
  {
    return mEndTagEnders;
  }

  public String[] getIds()
  {
    return mIds;
  }

  public String getLanguage()
  {
    return getAttribute("LANGUAGE");
  }

  public String getScriptCode()
  {
    String str;
    if (this.mCode != null)
      str = this.mCode;
    while (true)
    {
      return str;
      str = getChildrenHTML();
    }
  }

  public String getType()
  {
    return getAttribute("TYPE");
  }

  protected void putChildrenInto(StringBuffer paramStringBuffer, boolean paramBoolean)
  {
    if (getScriptCode() != null)
    {
      paramStringBuffer.append(getScriptCode());
      return;
    }
    SimpleNodeIterator localSimpleNodeIterator = children();
    while (true)
    {
      Node localNode;
      do
      {
        if (!(localSimpleNodeIterator.hasMoreNodes()));
        localNode = localSimpleNodeIterator.nextNode();
      }
      while ((paramBoolean) && (localNode.getStartPosition() == localNode.getEndPosition()));
      paramStringBuffer.append(localNode.toHtml(paramBoolean));
    }
  }

  public void setLanguage(String paramString)
  {
    setAttribute("LANGUAGE", paramString);
  }

  public void setScriptCode(String paramString)
  {
    this.mCode = paramString;
  }

  public void setType(String paramString)
  {
    setAttribute("TYPE", paramString);
  }

  public String toString()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("Script Node : \n");
    if ((getLanguage() != null) || (getType() != null))
    {
      localStringBuffer.append("Properties -->\n");
      if ((getLanguage() != null) && (getLanguage().length() != 0))
        localStringBuffer.append("[Language : " + getLanguage() + "]\n");
      if ((getType() != null) && (getType().length() != 0))
        localStringBuffer.append("[Type : " + getType() + "]\n");
    }
    localStringBuffer.append("\n");
    localStringBuffer.append("Code\n");
    localStringBuffer.append("****\n");
    localStringBuffer.append(getScriptCode() + "\n");
    return localStringBuffer.toString();
  }
}